<template>
  <div class="goodsDetail">
    <div class="content_nav" :class="{'roll':nav_show}">
      <div class="cart_nav topnav" @click="goBack()" :class="{'nobg':nav_show}">
        <svg-icon icon-class="return"/>
      </div>
      <div class="cart_nav" :class="{'nobg':nav_show}">
        <svg-icon icon-class="shoppingCard"/>
      </div>
      <div class="cart_nav share_nav" :class="{'nobg':nav_show}">
        <svg-icon icon-class="switch"/>
      </div>
      <div class="nav_img" v-show="nav_show==true"><img :src="swiperData[0]" alt=""></div>
      <div class="nav" v-show="nav_show==true" v-for="(item,index) in nav" :key="index" @click="jump(index)" :class="index==0?'current':''">{{item}}</div>
    </div>
    <div class="section">
      <!-- 顶部轮播图 -->
      <div class="carousel">
        <swiper :options="swiperOption" ref="mySwiper">
          <swiper-slide v-for="(item,index) in swiperData" :key="index">
            <img class="myswiper_img" :src="item" @click="swiperImgClick()">
          </swiper-slide>
          <div class="swiper-pagination" slot="pagination"></div>
        </swiper>
      </div>
      <!-- 价格信息 -->
      <div class="product_meta">
        <div class="price_meta">
          <div class="price">
            <span class="price_now">¥399</span>
            <span class="discount">¥9999</span>
          </div>
          <div class="sell_num">已销 9999 件</div>
        </div>
        <div class="desc">
          Candie's女装夏蕾丝气质秋连衣裙新款时尚韩版宽松长裙子仙蕾丝bf长袖气质连衣裙
        </div>
      </div>
      <div class="group-warp">
        <div class="sub1"><span class="fl">优惠</span><span class="mid">全网站商品通用</span><i class="icon"></i><span class="fr">领取</span></div>
        <div class="sub1"><span class="fl">促销</span><span class="mid">积分购买可得209积分</span><i class="icon"></i><span class="fr">领取</span></div>
        <div class="sub1"><span class="fl">服务</span><span class="mid">免举证退换货.极速退款</span><i class="icon"></i><span class="fr">领取</span></div>
      </div>
      <div class="group-warp">
        <div class="sub1"><span class="fl">选择</span><span class="mid">请选择机身颜色/类型</span><i class="icon"></i></div>
        <div class="sub1"><span class="fl">参数</span><span class="mid">品牌 型号...</span><i class="icon"></i></div>
      </div>
    </div>
    <div class="section">
      <div class="group-warp">
        <div class="comments">
          <div class="tt">
            <span class="fl">商品评价</span><span class="fr">查看全部<i class="icon"></i></span>
          </div>
          <div class="tag">
            <span>不错</span><span>符合描述</span><span>差评</span>
          </div>
          <div class="detail_comments">
            <div class="assess-flat" >
              <div class="assess-top">
                <span class="user-portrait">
                  <img src="../../images/zfund2.png" >
                </span>
                <span class="user-name">大卫</span>
                <span class="vip-icon vip-gold-icon"></span>
                <span class="assess-date">2016-09-23</span>
              </div>
              <div class="assess-bottom">
                <span class="comment-item-star">
                  <span class="real-star comment-stars-width5"></span>
                </span>
                <p class="assess-content">面料挺好 手感不错 没有色差 花纹好看 大小正好，不错 满意</p>
                <p class="pay-date">购买日期：2016-09-18 19:27:47</p>
                <p class="product-type">颜色：爱巢 型号：标准号200*230cm</p>
              </div>
              <div class="assess-btns-box">
                <div class="assess-btns">
                  <a class="btn_like" >
                    <i class="icon_like"></i>
                    <span >(0)</span>
                    <i class="like" >+1</i>
                  </a>
                  <a class="btn_like"   href="javascript:void(0)">
                    <i class="icon_like icon_reply"></i>
                    <span >(0)</span>
                  </a>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="section">
      <div class="group-warp">
        <div class="detail">
          <div class="tt">
            <span>店铺活动</span>
          </div>
          <img src="../../images/hdong.webp.jpg" alt="">
        </div>
      </div>
      <div class="group-warp">
        <div class="detail">
          <div class="tt">商品详情</div>
          <img :src="item" alt="" v-for="(item,index) in swiperData" :key="index">
        </div>
      </div>
      <div class="con_wrap">
        <router-view></router-view>
      </div>
    </div>

    <!-- 底部栏购物栏 -->
    <div class="shopcart">
      <div class="shop" >
        <div class="shop_img"></div>
        <span>店铺</span>
      </div>
      <div class="shop">
        <div class="shop_img col_img"></div>
        <span>收藏</span>
      </div>
      <div class="cart cart1"  @click="cart()">立即购买</div>
      <div class="cart"  @click="cart()">加入购物车</div>
    </div>
    <shop-cart  v-show="msg==true" @upup="change" :msg="msg"/>
  </div>

</template>

<script>
import { ImagePreview } from 'vant'
import 'swiper/dist/css/swiper.css'
import { swiper, swiperSlide } from 'vue-awesome-swiper'
import headTop from '../../components/header/head'
import shopCart from './cart/shopCart'

export default {
  name: 'goodsDetail',
  props: ['message'],

  components: {
    swiper,
    swiperSlide,
    headTop,
    shopCart,
    ImagePreview
  },
  data () {
    return {
      nav_show: '',
      swiperData: [
        '//h2.appsimg.com/a.appsimg.com/upload/merchandise/pdcvis/2018/07/20/161/fe69644b-04e6-46c5-8e3b-f750db9ef1e7_720x909_70.jpg',
        '//h2.appsimg.com/a.appsimg.com/upload/merchandise/pdcvis/2018/07/20/116/e1498661-f21f-45b3-9c7a-557684532133_720x909_70.jpg',
        '//h2.appsimg.com/a.appsimg.com/upload/merchandise/pdcvis/2018/07/20/148/802e9012-d83c-4c21-a219-436f82b51709_720x909_70.jpg',
        '//h2.appsimg.com/a.appsimg.com/upload/merchandise/pdcvis/2018/07/20/159/950fdbff-6359-4125-a2e2-6b8a997e30ec_720x909_70.jpg',
        '//h2.appsimg.com/a.appsimg.com/upload/merchandise/pdcvis/2018/07/20/26/938433c5-cc0a-44e0-9074-5249d873de20_720x909_70.jpg',
        '//h2.appsimg.com/a.appsimg.com/upload/merchandise/pdcvis/2018/07/20/84/5ae7b596-5c69-41c5-b9db-bef670f51760_720x909_70.jpg'
      ],
      swiperOption: {
        pagination: {
          el: '.swiper-pagination',
          dynamicBullets: true
        },
        autoplay: {
          delay: 2500,
          disableOnInteraction: false
        }
      },
      nav:['宝贝','评论','详情','溯源'],
      buy_tag: false,
      minus1: '',
      buy:true,
      msg:false,
      scroll: '',
    }
  },
  created () {},
  mounted () {
    window.addEventListener('scroll', this.handleScroll);
    window.addEventListener('scroll', this.dataScroll);

  },
  watch: {
    scroll: function () {
      this.loadSroll()
    }


  },
  computed: {},
  methods: {
    change(msg) {
      this.msg = msg;

    },

    destroyed () {
      window.removeEventListener('scroll', this.handleScroll)
    },
    cart () {
      this.msg = true
    },
    // 回退
    goBack () {
      this.$router.go(-1)
    },
    // 轮播图点击
    swiperImgClick () {
      // ImagePreview(this.swiperData)
    },
    handleScroll () {
      var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
      var offsetTop = document.querySelector('.content_nav').offsetTop
      if (scrollTop > offsetTop) {
        this.nav_show = true
      } else {
        this.nav_show = false
      }
    },
    // 去购物车页面
    gotoCart () {
      this.$router.push({
        path: '/cart'
      })
    },
    // 滚动事件
    dataScroll: function() {
      this.scroll = document.documentElement.scrollTop || document.body.scrollTop
    },
    jump(index) {
      let jump = document.getElementsByClassName('section') // 获取需要滚动的距离
      let total = jump[index].offsetTop                   // Chrome
      document.body.scrollTop = total                   // Firefox
      document.documentElement.scrollTop = total       // Safari
      window.pageYOffset = total                    //
      $('html, body').animate({                    //
        'scrollTop': total-100                    //
      }, 400)
    },
    loadSroll: function () {
      var self = this;
      var $navs = $('.nav');
      var sections = document.getElementsByClassName('section');
      for (var i = sections.length - 1; i >= 0; i--) {
        if (self.scroll >= sections[i].offsetTop - 100) {
          $navs.eq(i).addClass("actived").siblings().removeClass("actived")
          break;
        }
      }
    }
  }
}
</script>

<style lang="scss"  scoped>
  @import "../../style/common";
  @import "../../style/mixin";
  div{
    display: inline-block;
    width: 100%;
    font-size: 0.28rem;
    text-align: left;
  }
  div.goodsDetail {
    background:#f5f4f9;
    padding-bottom: 2rem;
    .content_nav{
      @include position(fixed,0,auto,0,auto);
      height:1.6rem;
      padding:0 0.2rem;
      z-index: 10;
      .nav_img{
        text-align: center;
        img{
          @include wh(1rem,1rem);
        }
      }
      div.nav{
        float: left;
        width:25%;
        text-align: center;
        color: #666;
        line-height: 0.52rem;
        &.actived{
          color: $bc2;
          background: url("../../images/map.png") no-repeat 22% center;
          background-size: 0.26rem;
        }

      }
    }
    .roll{
      background: #fff;
      border-bottom: 1px solid #f5f4f9;
    }
    .cart_nav{
       @include position(absolute,auto,0.8rem,0.166rem,auto);
       z-index: 1000;
       border-radius: 50%;
       background: rgba(0, 0, 0, 0.5);
       @include wh(0.5rem,0.5rem);
      svg{
        @include wh(0.36rem,0.36rem);
        margin-top: 0.07rem;
        z-index: 1000;
        margin-left: 0.08rem;
        color: #fff;
        float: left;

      }
    }
    .nobg{
      background: none;
      svg{
        fill:#888;
      }
    }
    .topnav {
        @include position(absolute,0.2rem,auto,0.166rem,auto);
          path{
            fill:#f00;
          }
    }
    .share_nav {
      @include position(absolute,auto,0.2rem,0.166rem,auto);
    }
    // 顶部轮播图
    .carousel {
      position: relative;
      /deep/ .swiper-pagination-bullet-active {
        background: #fff;
      }
      .myswiper_img {
        @include wh(100%,375px);
      }
    }
    // 价格信息
    .product_meta {
      padding: 0.32rem 0.32rem 0 0.32rem;
      background: #fff;
      .price_meta {
        @include fj(space-between);
        .price {
          .price_now {
            @include sc($fontsize,$themeColor);
            font-weight: 600;
          }
          .discount {
            @include sc($fontsize,$fontColor2);
            text-decoration: line-through;

          }
        }
        .sell_num {
          @include sc($fontsize,$fontColor2);
          text-align: right;
        }
      }
      .desc {
        margin-bottom: 0.32rem;
        text-overflow: ellipsis;
        /*text-overflow: -o-ellipsis-lastline;*/
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        line-height: 0.48rem;
      }
    }
    .group-warp{
      margin-top:0.1rem;
      line-height: 0.34rem;
      padding:0.1rem 0.2rem;
      background: #fff;
      .sub1{
        float: left;
        padding:0.1rem 0.06rem;
        span{
          height: 0.4rem;
          line-height: 0.4rem;

        }
        span.fl{
          font-size: 0.26rem;
          color: #999;
        }
        span.mid{
          float: left;
          color: #666;
          margin-left: 0.2rem;

        }
        i{
          background: url("../../images/back_light.png") no-repeat center center;
          background-size: auto 0.24rem;
          float: right;
          @include wh(0.24rem,0.38rem);
        }
      }
      .comments{
        padding: 0.1rem 0;
        .tt{
          margin-top: 0.1rem;
          span.fl{
            font-size:0.3rem;
          }
          span.fr{
            color: #F93943;
            i{
              background: url("../../images/back_light.png") no-repeat center center;
              background-size: auto 0.24rem;
              float: right;
              @include wh(0.24rem,0.28rem);
            }
          }
        }
        .tag{
          margin-top: 0.1rem;
          span{
            padding: 0.1rem 0.2rem;
            background: #FEE;
            border-radius: 0.3rem;
            float: left;
            margin-right: 0.1rem;
            font-size: 0.26rem;
          }
        }
      }
      .detail{
        .tt{
          padding: 0.1rem 0;
          text-align: left;
          font-size: 0.3rem;
        }
        img{
          width:100%;
        }
      }
    }
    .detail_comments{
      margin-bottom: .2rem;
      .assess-flat{
        padding: 0.1rem 0;
        color: #666;
        background: #fff;
        margin: 0.1rem 0;
        .assess-top{
          height: 0.8rem;
          line-height: 0.8rem;
          .user-portrait img{
            @include wh(0.7rem,0.7rem);
          }
          .user-name{
            font-size: 0.3rem;
            margin-left: 0.1rem;
          }
          .assess-date{
            float: right;
          }
        }
        .assess-bottom{
          padding-bottom: 0.2rem;
          border-bottom: 1px dashed #CFCFCF;
          .comment-item-star{
            height: 0.5rem;
            display: block;
            .real-star{
              height: 11px;
              background: url(../../images/comment-star.png) repeat-x 0 0;
              background-size: 15px 22px;
              width: 75px;
              margin-top: 8px;
              display: block;
            }
          }
          .assess-content{
          }
          .pay-date,.product-type{
            padding-top: 0.1rem;
            @include sc(0.24rem,#999);
          }
        }
        .assess-btns-box{
          .assess-btns {
            padding: 0.2rem;
            a{
              display: block;
              padding: .1rem 0;
              position: relative;
              width: 45%;
              text-align: center;
              border: 1px solid #e0e0e0;
              border-radius: 6px;
              margin: 0 0.1rem;
              float: left;
              &.btn_like{
                .icon_like{
                  background:url("../../images/assess-btns-icon.png") 0 0 no-repeat;
                  background-size:75px 15px;
                  @include wh(16px,16px);
                  float: left;
                  margin-left: 40%;
                }
                span{
                  float: left;
                  color: #666;
                }
                .like{
                  display: none;
                }
                .icon_reply{
                   background-position:-32px 0;
                }
              }
            }
          }
        }
      }
    }

    // 底部栏购物栏
    .shopcart {
      box-sizing: border-box;
      position: fixed;
      left: 0;
      bottom: 0;
      width: 100%;
      height: 1rem;
      flex-direction: row;
      justify-content: space-between;
      border-top: 1px solid #f5f4f9;
      align-items: center;
      padding: 0;
      background: #fff;
      .shop{
        height:1rem;
        float:left;
        width: 1.25rem;
        z-index: 1000;
        text-align: center;
        .shop_img{
          background: url("../../images/shop.png") no-repeat center center;
          height:0.6rem;
          background-size:auto 0.48rem ;
        }
        .col_img {
          background: url("../../images/collection.png") no-repeat center center;
          background-size:auto 0.52rem ;
        }
        span{
          font-size: 0.24rem;
          display: block;
        }

      }
      .cart {
        width: 2.5rem;
        height: 1rem;
        line-height: 1rem;
        text-align: center;
        background: #FF9500;
        color: #fff;
        font-size: 0.28rem;
        float: right;
      }
      .cart1{
        background: #FF0036;
      }
    }
  }
</style>
